|
| 1 | +import { |
| 2 | + OmnichannelSortingMechanismSettingType, |
| 3 | + type IOmnichannelServiceLevelAgreements, |
| 4 | + type Serialized, |
| 5 | +} from '@rocket.chat/core-typings'; |
| 6 | + |
| 7 | +import { createFakeVisitor } from '../../mocks/data'; |
| 8 | +import { IS_EE } from '../config/constants'; |
| 9 | +import { Users } from '../fixtures/userStates'; |
| 10 | +import { HomeOmnichannel } from '../page-objects'; |
| 11 | +import { OmnichannelRoomInfo } from '../page-objects/omnichannel-room-info'; |
| 12 | +import { createConversation } from '../utils/omnichannel/rooms'; |
| 13 | +import { createSLA } from '../utils/omnichannel/sla'; |
| 14 | +import { test, expect } from '../utils/test'; |
| 15 | + |
| 16 | +const visitorA = createFakeVisitor(); |
| 17 | +const visitorB = createFakeVisitor(); |
| 18 | +const visitorC = createFakeVisitor(); |
| 19 | + |
| 20 | +test.skip(!IS_EE, 'Omnichannel SLAs > Enterprise Only'); |
| 21 | + |
| 22 | +test.use({ storageState: Users.user1.state }); |
| 23 | + |
| 24 | +test.describe('OC - SLA Policies [Sidebar]', () => { |
| 25 | + let poHomeChannel: HomeOmnichannel; |
| 26 | + let poRoomInfo: OmnichannelRoomInfo; |
| 27 | + let conversations: Awaited<ReturnType<typeof createConversation>>[] = []; |
| 28 | + let slas: Serialized<Omit<IOmnichannelServiceLevelAgreements, '_updatedAt'>>[] = []; |
| 29 | + |
| 30 | + test.beforeAll('create SLAs', async ({ api }) => { |
| 31 | + slas = await Promise.all([ |
| 32 | + createSLA(api, { name: 'Very Urgent', dueTimeInMinutes: 1 }), |
| 33 | + createSLA(api, { name: 'Urgent', dueTimeInMinutes: 10 }), |
| 34 | + createSLA(api, { name: 'Not Urgent', dueTimeInMinutes: 30 }), |
| 35 | + ]); |
| 36 | + }); |
| 37 | + |
| 38 | + test.beforeAll(async ({ api }) => { |
| 39 | + ( |
| 40 | + await Promise.all([ |
| 41 | + // Create agent and manager |
| 42 | + api.post('/livechat/users/agent', { username: 'user1' }), |
| 43 | + api.post('/livechat/users/manager', { username: 'user1' }), |
| 44 | + // Settings |
| 45 | + api.post('/settings/Livechat_Routing_Method', { value: 'Manual_Selection' }), |
| 46 | + api.post('/settings/Omnichannel_sorting_mechanism', { value: OmnichannelSortingMechanismSettingType.SLAs }), |
| 47 | + ]) |
| 48 | + ).every((res) => expect(res.status()).toBe(200)); |
| 49 | + }); |
| 50 | + |
| 51 | + test.beforeEach(async ({ page }) => { |
| 52 | + poHomeChannel = new HomeOmnichannel(page); |
| 53 | + poRoomInfo = new OmnichannelRoomInfo(page); |
| 54 | + }); |
| 55 | + |
| 56 | + test.beforeEach(async ({ page }) => { |
| 57 | + await page.goto('/'); |
| 58 | + await page.locator('#main-content').waitFor(); |
| 59 | + }); |
| 60 | + |
| 61 | + test.beforeEach(async ({ api }) => { |
| 62 | + conversations = await Promise.all([ |
| 63 | + createConversation(api, { visitorName: visitorA.name, agentId: 'user1' }), |
| 64 | + createConversation(api, { visitorName: visitorB.name, agentId: 'user1' }), |
| 65 | + createConversation(api, { visitorName: visitorC.name, agentId: 'user1' }), |
| 66 | + ]); |
| 67 | + }); |
| 68 | + |
| 69 | + test.afterAll('delete SLAs', async ({ api }) => { |
| 70 | + const responses = await Promise.all(slas.map((sla) => api.delete(`/livechat/sla/${sla._id}`))); |
| 71 | + responses.every((res) => expect(res.status()).toBe(200)); |
| 72 | + }); |
| 73 | + |
| 74 | + test.afterAll(async ({ api }) => { |
| 75 | + // Delete conversations |
| 76 | + await Promise.all(conversations.map((conversation) => conversation.delete())); |
| 77 | + |
| 78 | + ( |
| 79 | + await Promise.all([ |
| 80 | + // Delete agent and manager |
| 81 | + api.delete('/livechat/users/agent/user1'), |
| 82 | + api.delete('/livechat/users/manager/user1'), |
| 83 | + // Reset settings |
| 84 | + api.post('/settings/Livechat_Routing_Method', { value: 'Auto_Selection' }), |
| 85 | + api.post('/settings/Omnichannel_sorting_mechanism', { value: OmnichannelSortingMechanismSettingType.Timestamp }), |
| 86 | + ]) |
| 87 | + ).every((res) => expect(res.status()).toBe(200)); |
| 88 | + }); |
| 89 | + |
| 90 | + test('OC - SLA Policies [Sidebar] - Update conversation SLA Policy', async () => { |
| 91 | + await test.step('expect to change room SLA policy to "Not urgent"', async () => { |
| 92 | + await test.step('expect to open room and room info to be visible', async () => { |
| 93 | + await poHomeChannel.sidenav.getSidebarItemByName(visitorA.name).click(); |
| 94 | + await expect(poRoomInfo.dialogRoomInfo).toBeVisible(); |
| 95 | + }); |
| 96 | + |
| 97 | + await test.step('expect to update room SLA policy', async () => { |
| 98 | + await expect(poRoomInfo.getInfoByLabel('SLA Policy')).not.toBeVisible(); |
| 99 | + await poRoomInfo.btnEditRoomInfo.click(); |
| 100 | + await poRoomInfo.selectSLA('Not Urgent'); |
| 101 | + await poRoomInfo.btnSaveEditRoom.click(); |
| 102 | + }); |
| 103 | + |
| 104 | + await test.step('expect SLA to have been updated in the room info and queue order to be correct', async () => { |
| 105 | + await expect(poRoomInfo.getInfoByLabel('SLA Policy')).toHaveText('Not Urgent'); |
| 106 | + await expect(poHomeChannel.sidenav.getSidebarListItemByName(visitorA.name)).toHaveAttribute('data-index', '1'); |
| 107 | + }); |
| 108 | + }); |
| 109 | + |
| 110 | + await test.step('expect to change room SLA policy to "Urgent"', async () => { |
| 111 | + await test.step('expect to open room and room info to be visible', async () => { |
| 112 | + await poHomeChannel.sidenav.getSidebarItemByName(visitorB.name).click(); |
| 113 | + await expect(poRoomInfo.dialogRoomInfo).toBeVisible(); |
| 114 | + }); |
| 115 | + |
| 116 | + await test.step('expect to update room SLA policy', async () => { |
| 117 | + await expect(poRoomInfo.getInfoByLabel('SLA Policy')).not.toBeVisible(); |
| 118 | + await poRoomInfo.btnEditRoomInfo.click(); |
| 119 | + await poRoomInfo.selectSLA('Urgent'); |
| 120 | + await poRoomInfo.btnSaveEditRoom.click(); |
| 121 | + }); |
| 122 | + |
| 123 | + await test.step('expect SLA to have been updated in the room info and queue order to be correct', async () => { |
| 124 | + await expect(poRoomInfo.getInfoByLabel('SLA Policy')).toHaveText('Urgent'); |
| 125 | + await expect(poHomeChannel.sidenav.getSidebarListItemByName(visitorB.name)).toHaveAttribute('data-index', '1'); |
| 126 | + await expect(poHomeChannel.sidenav.getSidebarListItemByName(visitorA.name)).toHaveAttribute('data-index', '2'); |
| 127 | + }); |
| 128 | + }); |
| 129 | + |
| 130 | + await test.step('expect to change room SLA policy to "Very Urgent"', async () => { |
| 131 | + await test.step('expect to open room and room info to be visible', async () => { |
| 132 | + await poHomeChannel.sidenav.getSidebarItemByName(visitorC.name).click(); |
| 133 | + await expect(poRoomInfo.dialogRoomInfo).toBeVisible(); |
| 134 | + }); |
| 135 | + |
| 136 | + await test.step('expect to update room SLA policy', async () => { |
| 137 | + await expect(poRoomInfo.getInfoByLabel('SLA Policy')).not.toBeVisible(); |
| 138 | + await poRoomInfo.btnEditRoomInfo.click(); |
| 139 | + await poRoomInfo.selectSLA('Very Urgent'); |
| 140 | + await poRoomInfo.btnSaveEditRoom.click(); |
| 141 | + }); |
| 142 | + |
| 143 | + await test.step('expect SLA to have been updated in the room info and queue order to be correct', async () => { |
| 144 | + await expect(poRoomInfo.getInfoByLabel('SLA Policy')).toHaveText('Very Urgent'); |
| 145 | + await expect(poHomeChannel.sidenav.getSidebarListItemByName(visitorC.name)).toHaveAttribute('data-index', '1'); |
| 146 | + await expect(poHomeChannel.sidenav.getSidebarListItemByName(visitorB.name)).toHaveAttribute('data-index', '2'); |
| 147 | + await expect(poHomeChannel.sidenav.getSidebarListItemByName(visitorA.name)).toHaveAttribute('data-index', '3'); |
| 148 | + }); |
| 149 | + }); |
| 150 | + }); |
| 151 | +}); |
0 commit comments